<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
#use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        if (Schema::hasTable('admins')) return;
        Schema::create('admins', function (Blueprint $table) {
            $table->id()->unsigned()->autoIncrement();
            $table->string('user_name')->default('')->index()->comment('登录名称');
            $table->string('real_name')->default('')->comment('姓名');
            $table->string('avatar')->default('')->comment('头像');
            $table->string('mobile', 11)->default('')->comment('手机号');
            $table->string('pass_word', 50)->default('')->comment('账户密码');
            $table->unsignedBigInteger('role_id')->default(0)->comment('角色ID，管理roles表ID');
            $table->boolean('is_enable')->default(1)->comment('是否启用：1是 0否');
            $table->boolean('is_delete')->default(0)->comment('是否删除：1是 0否');
            $table->string('token')->default('')->comment('登录token');
            $table->string('last_login_ip')->default('')->comment('上次登录IP');
            $table->string('last_login_at')->default(\App\Consts\TimeConst::DEFAULT_DATE_TIME)->comment('上次登录时间');
            $table->dateTime('created_at')->default(\DB::raw('CURRENT_TIMESTAMP'));
            $table->timestamp('updated_at')->default(\DB::raw('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'));
        });
        DB::statement("ALTER TABLE `admins` COMMENT '管理员'");
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        if (!is_production()) Schema::dropIfExists('admins');
    }
};
